/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lucava.boatskeeper.client.view;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

/**
 *
 * @author glenn
 */
public class SimpleImageCell extends AbstractCell<String> {

    interface Template extends SafeHtmlTemplates {

        @Template("<img src=\"{0}\" style=\"width:50px;\"/>")  // 20*20 size
        SafeHtml img(String url);
    }
    private static Template template;

    /**
     * Construct a new MyImageCell.
     */
    public SimpleImageCell() {
        if (template == null) {
            template = GWT.create(Template.class);
        }
    }

    @Override
    public void render(Context context, String value, SafeHtmlBuilder sb) {
        if (value != null) {
            // The template will sanitize the URI.
            sb.append(template.img(value));
        }
    }
}